package com.letu.core.utils;

import com.letu.core.dynamic.FieldType;

/**
 * Date:2021/8/6
 * Time:13:52
 *
 * @author zjn
 */
public class StringUtils {

    public static String capitalize(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return str;
        }
        return new StringBuilder(strLen).append(Character.toTitleCase(str.charAt(0))).append(str.substring(1)).toString();
    }

    public static Object convertToClass(String str, Class clazz) {
        if (FieldType.STRING.getClazz().equals(clazz)) {
            return str;
        } else if (FieldType.BOOLEAN.getClazz().equals(clazz)) {
            return Boolean.valueOf(str);
        } else if (FieldType.INTEGER.getClazz().equals(clazz)) {
            return Integer.valueOf(str);
        } else if (FieldType.LONG.getClazz().equals(clazz)) {
            return Long.valueOf(str);
        } else if (FieldType.LOCAL_DATE_TIME.getClazz().equals(clazz)) {
            return DateUtils.date2LocalDateTime(DateUtils.parseAsDateTime(str));
        } else {
            return str;
        }
    }

    public static boolean isBlank(String value) {
        if (value == null || value.length() == 0) {
            return true;
        }
        for (int i = 0; i < value.length(); i++) {
            if (!Character.isSpaceChar(value.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    public static boolean isBlank(String... values) {
        if (null == values || values.length == 0) {
            return true;
        }
        for (String value : values) {
            if (isBlank(value)) {
                return true;
            }
        }
        return false;
    }

}
